
import {JSJaCPacket} from './JSJaCPacket'
/**
 * A jabber/XMPP presence packet
 * @class Models the XMPP notion of a 'presence' packet
 * @extends JSJaCPacket
 */
export class JSJaCPresence extends JSJaCPacket {
    constructor() {
        super('presence')
    }
    /**
     * Sets the status message for current status. Usually this is set
     * to some human readable string indicating what the user is
     * doing/feel like currently.
     * @param {string} status A status message
     * @return {JSJaCPresence} this
     */
    setStatus(status:string):JSJaCPresence {
      this._setChildNode("status", status);
      return this;
    };
    /**
     * Sets the online status for this presence packet.
     * @param {string} show An XMPP complient status indicator. Must
     * be one of 'chat', 'away', 'xa', 'dnd'
     * @return {JSJaCPresence} this
     */
    setShow(show:string):JSJaCPresence {
      if (show == 'chat' || show == 'away' || show == 'xa' || show == 'dnd')
        this._setChildNode("show",show);
      return this;
    };
    /**
     * Sets the priority of the resource bind to with this connection
     * @param {int} prio The priority to set this resource to
     * @return {JSJaCPresence} this
     */
    setPriority(prio:number):JSJaCPresence {
      this._setChildNode("priority", prio.toString());
      return this;
    };
    /**
     * Some combined method that allowes for setting show, status and
     * priority at once
     * @param {string} show A status message
     * @param {string} status A status indicator as defined by XMPP
     * @param {int} prio A priority for this resource
     * @return {JSJaCPresence} this
     */
    setPresence(show:string,status:string,prio:number):JSJaCPresence {
      if (show)
        this.setShow(show);
      if (status)
        this.setStatus(status);
      if (prio)
        this.setPriority(prio);
      return this;
    };
    
    /**
     * Gets the status message of this presence
     * @return The (human readable) status message
     * @type String
     */
    getStatus():string {
      return this.getChildVal('status');
    };
    /**
     * Gets the status of this presence.
     * Either one of 'chat', 'away', 'xa' or 'dnd' or null.
     * @return The status indicator as defined by XMPP
     * @type String
     */
    getShow():string {
      return this.getChildVal('show');
    };
    /**
     * Gets the priority of this status message
     * @return A resource priority
     * @type int
     */
    getPriority():string {
      return this.getChildVal('priority');
    };

    clone(): JSJaCPacket {
      let oPacket:JSJaCPresence= new JSJaCPresence();
      oPacket.setDoc(this.getDoc().clone())
      return oPacket;
    }

}